﻿/*
 *QUERY面板基类,继承自EXT的Panel
 */
peanut.QueryPanel = Ext.extend(Ext.Panel, {
    
    /**
      *基本属性
      */
    gridPanel:null,
    gridPanelId: 'gridPanel' + this.ID,
    gridViewConfig: {},
    cm: new Ext.grid.CellSelectionModel(),
    sm: new Ext.grid.RowSelectionModel({
		dataIndex: this.ID
	}),//-列选择模式
    store: null,
    storeMapping: null,
    pageSize: null,
    
    keywordText: null,
    
    baseUrl: null,
    renderTo:null,
    
    width: '100%',
    height: '100%',
 
    //构造器
    constructor: function(config){
        
        config = config || {};
        this.pageSize = config.pageSize || EXT_PAGE_SIZE;
        
        var flag = this.store == null;
        
        if(flag){
            this.store = new Ext.data.JsonStore({
                id: this.ID,
                url: this.baseUrl + '?cmd=List',//默认的数据源地址，继承时需要提供
                root: "pagingRows",
                totalProperty: "totalRows",
                remoteSort: true,
                fields: this.storeMapping
            });
        } 
        
        this.cm.defaultSortable = true;
        
        var viewConfig = Ext.apply({
            forceFit: true
        }, this.gridViewConfig);
        
        this.gridPanel = new Ext.grid.GridPanel({
            id:Ext.id(),
            store:this.store,
            cm:this.cm,
            sm:this.sm,
            //autoHeight:true,
            height:600,
            trackMouseOver:false,
            labelStyle:'font-weight:bold;',
            anchor:'100%',
            loadMask: true,
            //超过长度带自动滚动条
		    autoScroll:true,
		    border:false,
		    //collapsible: true,
            animCollapse:false,
            viewConfig:viewConfig,
            listeners: {
                //'celldblclick': {//双击时执行修改
                    //fn: this.onEdit,
                    //scope: this
                //},
                'contextmenu':function(e) {
                    e.stopEvent();
                },
                'cellcontextmenu':function(Grid,Rindex,Cindex,E){
        			//var store = Grid.getStore();
        			//var dataList = store.data.items;
        			//var fieldList = store.fields.items;
        			//console.info(dataList);
        			//console.info(fieldList[Cindex]['name']);
        			//console.info(dataList[Rindex].data[fieldList[Cindex - 1]['name']]);
			    }
            },
            tbar:config.fp,
            //分页
            bbar: new Ext.PagingToolbar({
                pageSize: this.pageSize,
                store: this.store,
                buttonAlign:'right'
            })
        });
        
        //this.gridPanel.bbar = null;
        
        if(this.view){
            Ext.apply(this.gridPanel,{
                view: this.view
            });
        }
        
        this.store.load({
            params: {
                start: 0,
                limit: this.pageSize
            }
        });
        
        var configs = Ext.apply({
            closable: true,
            autoScroll: true,
            layout: "anchor",
            items:[this.gridPanel],
            /**
              *渲染数据
              */
            //链接
            linkRenderer: function(v){
                if (!v) 
                    return "";
                else 
                    return String.format("<a href='{0}' target='_blank'>{0}</a>", v);
            },
            //时间
            dateRender: function(format){
                format = format || "Y-m-d h:i";
                return Ext.util.Format.dateRenderer(format);
            }
        },config);
        //调用父类的构造器
        peanut.QueryPanel.superclass.constructor.call(this,configs);
    },
       
    /**
      *事件
      */
    //刷新
    onRefresh: function(){
        this.store.removeAll();
        this.store.reload();
    }
});
